<template>
  <div>
    <!-- 头部 -->
    <top :f1="true" :f2="false"></top>
    <!-- 主体 -->
    <van-cell-group>
      <van-field v-model="value" placeholder="请输入商品名称" />
    </van-cell-group>
    <van-button type="info" size="large" @click="addGoods">添加商品</van-button>
    <!-- 底部 -->
    <bottom></bottom>
  </div>
</template>

<script>
export default {
  data() {
    return {
      value: ''
    }
  },
  created() {},
  methods: {
    async addGoods() {
      const { data: res } = await this.axios.post('/api/addproduct', {
        name: this.value
      })
      if (res.status !== 0) {
        return this.$store('添加商品失败')
      }
      this.$router.push('/search')
      this.$notify({
        message: '添加成功',
        duration: 1000,
        background: 'green'
      })
    }
  }
}
</script>

<style lang="less" scoped>
.van-cell-group {
  padding: 0 10px;
  position: relative;
  top: 40px;
}
.van-button--large {
  height: 40px;
  background: #1989fa;
  border: 1px solid #1989fa;
  line-height: 38px;
  margin: 80px 0;
  width: 90%;
  transform: translateX(20px);
}
</style>
